<template>
  <div class="cpsy_box">
    <header-comm></header-comm>

    <div class="bcg">
      <div class="header_sele">
        <div class="add_qy"></div>
        <div>
          <div class="list_head">
            <div class="fl_right">
              <div class="seach">
                <div class="sele">
                  <a-radio-group name="radioGroup" :default-value="csppkey" @change="cpsykeyword">
                    <a-radio :value="0">全部</a-radio>
                    <a-radio :value="1">已匹配</a-radio>
                    <a-radio :value="2">未匹配</a-radio>

                  </a-radio-group>
                </div>
              </div>
              <div class="seach">
                <div class="sele">
                  型号查询：
                  <a-input placeholder="请输入型号" style="width: 250px" @change="onSearchxl" />
                  <a-icon type="search" class="search" />
                </div>
              </div>
              <div class="seach">
                <div class="sele">
                  品牌查询：
                  <a-input placeholder="请输入品牌" style="width: 250px" @change="onSearchpp" />
                  <a-icon type="search" class="search" />
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="hedlistbtn">
        <a-badge
          @click="ztclick(0)"
          :class="sx_active==0?'sx_active':''"
          class="sx_pp"
          :count="totalNum"
          :number-style="{ backgroundColor: 'rgb(58, 142, 228)' }"
          :overflowCount="totalNum"
        >
          <span>当前</span>
        </a-badge>
        <a-badge
          @click="ztclick(1)"
          :class="sx_active==1?'sx_active':''"
          class="sx_pp"
          :count="isTrueMatchNum"
          :overflowCount="isTrueMatchNum"
          :number-style="{ backgroundColor: '#52c41a' }"
        >
          <span>已匹配</span>
        </a-badge>

        <a-badge
          @click="ztclick(2)"
          :class="sx_active==2?'sx_active':''"
          class="sx_pp"
          :overflowCount="isFalseMatchNum"
          :count="isFalseMatchNum"
        >
          <span>未匹配</span>
        </a-badge>
      </div>
      <div class="cpsy">
        <!-- <xzl v-if="$store.state.xzlflg"></xzl> -->
        <a-table
          @change="handleChangelist"
          :loading="loading"
          :columns="columns"
          :pagination="pagination"
          :dataSource="data"
        >
          <template slot="ppzt" slot-scope="text, record, index">
            <a-tag color="#ff3040" v-if="record.spbm==null?true:false">未匹配</a-tag>
            <a-tag color="#87d068" v-if="record.spbm!=null?true:false">已匹配</a-tag>
          </template>
          <template slot="bzcs" slot-scope="text, record, index">
            <div>{{record.spbm_xl}}---{{record.spbm_sccjc}}</div>
          </template>
          <template slot="spbm" slot-scope="text, record, index">
            <div>
              <!-- {{text}} -->
              <span class="spbm_ck del" @click="plsele(record)">请选择</span>
              <span @click="clear(record)" class="del">清空</span>
            </div>
          </template>
        </a-table>
      </div>
      <div class="cpsy_tk" v-if="cpsytkflag">
        <cpsytk></cpsytk>
      </div>
    </div>
  </div>
</template>

<script>
import qs from "qs";
const plainOptions = ["推荐"];
const defaultCheckedList = [""];
const checkedList = ["推荐"];

const columns = [
  {
    title: "型号",
    dataIndex: "XL"
  },
  {
    title: "品牌",
    dataIndex: "SCCJC"
  },
  {
    title: "标准参数名称",
    dataIndex: "bzcs",
    scopedSlots: { customRender: "bzcs" }
  },

  {
    title: "匹配状态",
    dataIndex: "ppzt",
    scopedSlots: { customRender: "ppzt" }
  },
  {
    title: "操作",
    dataIndex: "spbm",
    scopedSlots: { customRender: "spbm" }
  }
  //   {
  //     title: "操作",
  //     dataIndex: "operation",
  //     scopedSlots: { customRender: "operation" }
  //   }
];
import headerComm from "../header-comm/header.vue";
import cpsytk from "./cpsy_tk.vue";
const data = [];

export default {
  inject: ["reload"],

  data() {
    this.cacheData = data.map(item => ({ ...item }));

    return {
      data,
      columns,
      dckcflag: false,
      sele: "",
      xlserchvalue: "",
      ppserchvalue: "",
      pagination: {
        defaultPageSize: 10,
        showTotal: total => `共 ${total} 条数据`,
        total: 0,
        current: 1
      },
      totalNum: 0,
      isFalseMatchNum: 0,
      isTrueMatchNum: 0,
      isAndMatchNum: 0,
      cpsy_value: "",
      cpsytkflag: false,
      sx_active: 0,
      flcx: "",
      loading: true,
      cpsqdwid: "", //授权单位
      datakh: [],
      khvalue: "",
      selectedRowKeys: [],
      fyflag: false,
      cpfllist: [],
      checkedList: defaultCheckedList,
      plainOptions,
      nbdwmc: "", //寄售公司名称
      nbdwbm: "", //寄售公司手机号码
      applyment_state: sessionStorage.getItem("applymentstate"),
      wlkhjb: sessionStorage.getItem("wlkhjb"),
      csppkey:0
    };
  },
  components: {
    headerComm,
    cpsytk
  },
  methods: {
    //现货数据查询
    onSearchxl(e) {
      this.xlserchvalue = e.target.value;
      this.handleChangelist(this.pagination);
    },
    onSearchpp(e) {
      this.ppserchvalue = e.target.value;
      this.handleChangelist(this.pagination);
    },

    //库存数据列表
    handleChangelist(pagination, matching) {
      // this.pagination = pagination;
      this.pagination.current = pagination.current;
      this.axios
        .post(
          "kucunSpbm/kucunSpbmList.php",
          qs.stringify({
            sqdwid: this.$store.state.bbl_sqdwid,
            page: this.pagination.current,
            pageSize: pagination.defaultPageSize,
            xl: this.xlserchvalue,
            sccjc: this.ppserchvalue,
            spbm: "",
            // matching: this.sx_active,
            matching: this.csppkey,
            
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.data = res.data.result.data;
            this.isFalseMatchNum = Number(res.data.isFalseMatchNum);
            this.isTrueMatchNum = Number(res.data.isTrueMatchNum);
            this.totalNum = Number(res.data.totalNum);
            this.pagination.total = Number(res.data.result.total);
            this.loading = false;
            this.cacheData = this.data.map(item => ({
              ...item
            }));
            for (var i = 0; i < res.data.result.data.length; i++) {
              this.data[i].key = res.data.result.data[i].ID_NUM;
              // console.log('ssssssssssssssspix',res.data.result.data[i].pic)
              if (
                res.data.result.data[i].pic != " " &&
                res.data.result.data[i].pic != null
              ) {
                this.data[i].pic = res.data.result.data[i].pic.split(",");
                //    console.log('spix',this.data[i].pic)
              }
            }
            sessionStorage.setItem("total", res.data.result.total);
          } else {
            this.data = [];

            this.loading = false;
          }
        });
    },
    cpsykeyword(e){
         this.csppkey =e.target.value
         this.handleChangelist(this.pagination)
    },
    ztclick(key) {
      console.log(key);
      this.sx_active = key;
      this.pagination.current = 1;
      this.handleChangelist(this.pagination, key);

      // $('.sx_pp').addClass("sx_active").siblings().removeClass("sx_active")
    },

    plsj(isupset) {
      this.axios
        .post(
          "kucun/putOnSaleAll.php",
          qs.stringify({
            sqdwid: this.$store.state.bbl_sqdwid,
            phone: this.$store.state.bbl_phone,
            isupset: isupset
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
            this.handleChangelist(this.pagination);
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    // plxj() {
    //   console.log("000000000");
    // },
    //批量excel导入
    pldr() {
      this.$store.state.cpscym = true;
    },

    sjcp(value, key) {
      this.axios
        .post(
          "kucun/putOnSale.php",
          qs.stringify({
            id_num: value.ID_NUM,
            isupset: value.jsbj == "是" || value.shop == "是" ? 0 : 1,
            phone: this.$store.state.bbl_phone
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
            this.handleChangelist(this.pagination);
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    clear(value) {
      this.axios
        .post(
          "kucunSpbm/kucunSpbmReset.php",
          qs.stringify({
            id_num: value.ID_NUM,
            xl: value.XL,
            sccjc: value.SCCJC,
            sqdwid: this.$store.state.bbl_sqdwid
          })
        )
        .then(res => {
          console.log(res);
          if (res.data.code == 303) {
            this.$notification["success"]({
              message: "成功",
              description: res.data.msg
            });
            this.handleChangelist(this.pagination);
          } else {
            this.$notification["error"]({
              message: "失败",
              description: res.data.msg
            });
          }
        });
    },
    //分类列表
    getfllist() {
      this.axios
        .post(
          "kucun/SelectProList.php",
          qs.stringify({
            // pro: this.flcx,
            sqdwid: this.$store.state.bbl_sqdwid,
            num: 100
          })
        )
        .then(res => {
          if (res.data.code == 303) {
            this.cpfllist = [];

            for (var i = 0; i < res.data.result.length; i++) {
              this.cpfllist.push(res.data.result[i].proName);
            }
          }
        });
    },
    //产品分类列表
    flchange(value) {
      this.flcx = value;
      console.log(value);
      this.pagination.current = 1;
      this.handleChangelist(this.pagination);
      // this.getfllist();
    },
    plsele(value) {
      console.log(value);
      this.cpsy_value = value;
      this.cpsytkflag = true;
    }
  },
  computed: {
    rowSelection() {
      const { selectedRowKeys } = this;

      return {
        onChange: (selectedRowKeys, selectedRows) => {
          this.selectedRowKeys = selectedRowKeys;
        }
      };
    }
  },

  created() {
    this.handleChangelist(this.pagination);
    this.getfllist();
  }
};
</script>

<style lang='less' scoped>
.cpsy_box {
  .hedlistbtn {
    display: block;
    .ant-badge {
      margin: 0 30px;
    }
    .sx_pp {
      padding: 10px 15px;
      cursor: pointer;
    }
    .sx_active {
      border-bottom: 2px solid rgb(50, 103, 250);
    }
  }
  .header_sele {
    position: absolute;
    top: 55px;
    left: 1% !important;
    z-index: 999;
    text-align: right;
    width: 98% !important;
    background-color: #fff;
    box-shadow: 5px 5px 5px #ccc;
    // height: 50px;
    padding: 10px 20px;
    margin: 10px 0 !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .add_qy {
      // width: 50%;
      display: inline-block;
      text-align: left;
      padding: 10px 0;
      height: 50px !important;
      button {
        margin: 0 10px;
      }
      .ant-btn-primary {
        background-color: #1890ff !important;
        border: 0 !important;
      }
    }
    .seach {
      display: inline-block;
      margin-right: 20px;
      .sele {
        position: relative;
        i {
          position: absolute;
          top: 10px;
          right: 8px;
        }
      }
    }
    .list_head {
      display: inline-block;
      .tit {
        font-size: 16px;
      }
      padding: 10px 15px;
      .fl_right {
        .margin {
          margin: 0 5px;
        }
        .xzl_btn:hover {
          border: 0 !important;
          color: #fff !important;
          background: #1890ff !important;
        }
      }
    }
  }
  .spbm_ck {
    color: #c00;
    cursor: pointer;
  }

  .cpsy {
    width: 98%;
    position: relative;
    top: 141px;
    left: 1%;
    background-color: #fff;
    border: 1px solid #ccc;
    .ant-table-thead > tr,
    .ant-table-tbody > tr {
      height: 50px !important;
    }
  }
  .fyloading {
    position: absolute;
    width: 90% !important;
    border: 1px solid #91d5ff;
    background: rgba(255, 255, 255, 0.5);
    padding: 30px;
    height: 800px !important;
    z-index: 999999 !important;
    top: 108px;
    left: 201px;
    // opacity: .5!important;
    .ant-spin-blur {
      opacity: 1 !important;
    }
    .ant-spin-text {
      font-size: 18px !important;
    }
  }
  .ant-spin-nested-loading > div > .ant-spin {
    position: relative !important;
    top: 100px !important;
  }
  .del {
    padding-right: 5px !important;
    color: #40a9ff;
    cursor: pointer;
  }
  .cpsy_tk {
    position: fixed;
    z-index: 999;
    top: 0;
    left: 0;
    width: 100%;
    height: 1000px;
    background: rgba(0, 0, 0, 0.5);
  }
}
</style>
